const coWechat = require('co-wechat');
const { cConfig } = require('../config');
const chalk = require('chalk');
module.exports =
    coWechat(cConfig, true).middleware(async (message, ctx) => {
        console.log(chalk.bgMagenta(JSON.stringify(message)));

        /* api.createMenu(menu, function (err, result) {
            if (err) {
                throw err
            };
            console.log('appMenu', result);
        }); */
        // 微信输入信息就是这个 message
        if (message.FromUserName === 'diaosi') {
            // 回复屌丝(普通回复)
            return 'hehe';
        } else if (message.FromUserName === 'text') {
            //你也可以这样回复text类型的信息
            return {
                content: 'text object',
                type: 'text'
            };
        } else if (message.Content === 'hehe') {
            // 回复一段音乐
            return {
                type: "music",
                content: {
                    title: "来段音乐吧",
                    description: "一无所有",
                    musicUrl: "http://mp3.com/xx.mp3",
                    hqMusicUrl: "http://mp3.com/xx.mp3"
                }
            };
        } else if (message.Content === 'xc') {
            // 回复一段音乐
            return {
                type: 'text',
                content: `<a data-miniprogram-appid="wx24a21b47e8d32f78" 
                        data-miniprogram-path="pages/Home/Home" 
                        href="http://www.qq.com">كىنوخانىغا كىرىڭ</a>`
            };
        }
        else if (message.FromUserName === 'kf') {
            // 转发到客服接口
            return {
                type: "customerService",
                kfAccount: "test1@test"
            };
        } else {
            // 回复高富帅(图文回复)
            return {
                type: 'text',
                content: `<a data-miniprogram-appid="wx24a21b47e8d32f78" 
                        data-miniprogram-path="pages/Home/Home" 
                        href="http://www.qq.com">كىنوخانىغا كىرىڭ</a>`
            }
            /*  return [{
                 title: 'مارس كىنوخانىسى',
                 description: 'كىنوخانىمىزغا كەلگىنىڭىزنى قارشى ئالىمىز',
                 picurl: 'http://nodeapi.cloudfoundry.com/qrcode.jpg',
                 url: 'http://nodeapi.cloudfoundry.com/'
             }]; */
        }
    });



/* var weixin = {
    appid: 'appid',
    appsecret: 'appsecret',
    prefix: 'https://api.weixin.qq.com/cgi-bin/',
    mpPrefix: 'https://mp.weixin.qq.com/cgi-bin/',
    fileServerPrefix: 'http://file.api.weixin.qq.com/cgi-bin/',
    payPrefix: 'https://api.weixin.qq.com/pay/',
    merchantPrefix: 'https://api.weixin.qq.com/merchant/',
    customservicePrefix: 'https://api.weixin.qq.com/customservice/'
}
*/